﻿using Assets.Scripts.DL.ComponentScripts;
using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Enemy.CommonEnemy;
using Assets.Scripts.DL.Enemy.CommonEnemy.States.Special;
using Assets.Scripts.DL.Mgrs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEngine;

namespace Assets.Scripts.DL.Enemy.YaSuo {
	//CommonFSM转导ATK的条件需要添加一个或，即检测到玩家的远程，还是需要重写
	public class YasuoWindWall : CommonState<YasuoController> {
		bool _wallsend;
		Timer _backTimer = new();
		public YasuoWindWall(YasuoController controller, StateEnum stateName) : base(controller, stateName) {
			AddConditionToSelf(() => _controller.DetectPlayerRemoteAtk());
		}

		public override void Enter() {
			//_controller.Velocity = Vector2.zero;
			//Debug.Log("Windwall");
			_controller.PlayAnim(StateEnum.Atk1);
			_wallsend = false;
			var dir = _controller.transform.localScale.x;
			_controller.Velocity = new UnityEngine.Vector2(-dir * _controller.ESpeed, 0);
			//Debug.Log(_controller.Velocity);
			_backTimer.Reset();
		}

		public override void Exit() {
		}

		public override void Update() {
			//Debug.Log(_controller.Velocity);
			if (_backTimer.Elapsed > 1) {
				_controller.Velocity = Vector2.zero;
			}
			if (_controller.IsAnimPlayAt(0.5f) && !_wallsend) {
				//生成问wal
				AudioManager.Play(_controller.Voice2, AudioStr.WindWallVoice, false);
				var dir = _controller.FaceDir;
				var off = _controller.WindOffset;
				//var pos = _controller.transform.position + new
				var pos = _controller.transform.position + new Vector3(dir * off.x, 0);
				var obj = ObjectPool.Instance.GetObject(ObjPoolStr.WindWall);
				obj.GetComponent<WindWall>().Init(pos, dir);
				_wallsend = true;
			}
			if (_wallsend && _controller.IsAnimPlayOver()) {
				_controller.StateData.AtkOver = true;
			}
		}
	}
}
